package com.liuqh.tag.easyexcel;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import lombok.Getter;
import lombok.Setter;

/**
 * @Description TODO(这里用一句话描述这个类的作用)
 *
 * @author liuqinghua
 * @date 2024-6-20
 */
@Getter
@Setter
public class ParseListen extends AnalysisEventListener<DicData> {
    private String parentCode = null;
    private String parentName = null;
    private List<OutDicData> outDataList = new ArrayList<OutDicData>();
    private int seq;

    @Override
    public void invoke(DicData data, AnalysisContext context) {
        seq++;
        OutDicData od = new OutDicData();
        String typeName = "学科";
        String typeCode = "SUBJECT";
        String pname = data.getPname();
        if (StringUtils.isNotBlank(pname)) {
            parentCode = pname.substring(0, 4);
            parentName = pname.substring(4);
            String dicId = typeCode + "_" + parentCode;
            od.setDicId(dicId);
            od.setTypeCode(typeCode);
            od.setTypeName(typeName);
            od.setPcode("500");
            od.setSeq(seq);
            od.setCode(parentCode);
            od.setName(parentName);
            System.out.println(parentCode + " " + parentName);
        } else {
            String dicId = typeCode + "_" + data.getCode();
            System.out.println(parentCode + " " + data.getCode() + " " + data.getName());
            od.setDicId(dicId);
            od.setTypeCode(typeCode);
            od.setTypeName(typeName);
            od.setPcode(parentCode);
            od.setSeq(seq);
            od.setCode(data.getCode());
            od.setName(data.getName());
        }
        outDataList.add(od);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }

}
